home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- '''Verify that warnings are issued for global statements following use.'''
- from test.test_support import check_syntax
- import warnings
- warnings.filterwarnings('error', module = '<test code>')
-
- def compile_and_check(text, should_fail = 1):
-
- try:
- compile(text, '<test code>', 'exec')
- except SyntaxError:
- msg = None
- if should_fail:
- print 'got SyntaxError as expected'
- else:
- print 'raised unexpected SyntaxError:', text
- except:
- should_fail
-
- if should_fail:
- print 'should have raised SyntaxError:', text
- else:
- print 'as expected, no SyntaxError'
-
- prog_text_1 = '\ndef wrong1():\n a = 1\n b = 2\n global a\n global b\n'
- compile_and_check(prog_text_1)
- prog_text_2 = '\ndef wrong2():\n print x\n global x\n'
- compile_and_check(prog_text_2)
- prog_text_3 = '\ndef wrong3():\n print x\n x = 2\n global x\n'
- compile_and_check(prog_text_3)
- prog_text_4 = '\nglobal x\nx = 2\n'
- compile_and_check(prog_text_4, 0)
-